package vn.com.tiz.DocumentZ.test;

import vn.com.tiz.DocumentZ.utils.LogTools;
import vn.com.tiz.DocumentZ.view.ScrollViewEx;
import vn.com.tiz.DocumentZ.view.VideoViewer;
import android.app.Activity;
import android.graphics.Color;
import android.net.Uri;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.VideoView;

public class actTestVideo extends Activity {

	//VideoView videoView;
	VideoViewer video;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.test_video);
	
		//LinearLayout videoContainer = (LinearLayout)findViewById(R.id.lnearVideoContainer);
		ScrollViewEx sMain = new ScrollViewEx(this);
		
		
		LinearLayout videoContainer = new LinearLayout(this);
		
		for(int i = 0;i<10;i++){
			TextView txv = new TextView(this);
			txv.setText("Text");
			videoContainer.addView(txv);
			//video.
		}
		
		LinearLayout lnearControl = new LinearLayout(this);
		lnearControl.setOrientation(LinearLayout.HORIZONTAL);
		Button btnPlay = new Button(this);
		btnPlay.setText("Play");
		
		Button btnPause = new Button(this);
		btnPause.setText("Pause");
		btnPause.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				video.pause();
				//video.removeCallback();
			}
		});
		
		btnPlay.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				video.setVideoURI(Uri.parse("/mnt/sdcard/TheRoad.mp4"));
				video.play();
				
			}
		});
		
		Button btnStop = new Button(this);
		btnStop.setText("Resume");
		btnStop.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				video.resume();
			}
		});
		
		lnearControl.addView(btnPlay);
		lnearControl.addView(btnPause);
		lnearControl.addView(btnStop);
		
		videoContainer.setOrientation(LinearLayout.VERTICAL);
		videoContainer.addView(lnearControl);
		//videoContainer.addView(btnStop);
		
		videoContainer.setBackgroundColor(Color.GRAY);
		video = new VideoViewer(this);
		//setContentView(video);
		
		videoContainer.addView(video);
		sMain.addView(videoContainer);
		//setContentView(videoContainer);
		setContentView(sMain);
		for(int i = 0;i<50;i++){
			TextView txv = new TextView(this);
			txv.setText("Text");
			videoContainer.addView(txv);
		}
		
		sMain.setOnScrolling(new ScrollViewEx.OnScrolling() {
			
			public void Scrolling() {
				// TODO Auto-generated method stub
				video.refreshLayout();
				//video.setVideoURI(Uri.parse("/mnt/sdcard/TheRoad.mp4"));
			}
		});
		LogTools.memoryUsedinfo();		
		//video.setVideoURI(Uri.parse("/mnt/sdcard/TheRoad.mp4"));
		//LogTools.memoryUsedinfo();
		
		//video.play();

		//video.setVideoPath("/mnt/sdcard/TheRoad.mp4");
		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		//video.resume();
	}
	
	  @Override
	    protected void onPause() {
	        super.onPause();
	        //video.pause();
	        //video.releaseMediaPlayer();
	        //video.doCleanUp();
	    }

	    @Override
	    protected void onDestroy() {
	        super.onDestroy();
	        video.releaseMediaPlayer();
	        video.doCleanUp();
	        System.runFinalization();
	        System.exit(0);
	    }
}
